import React, { FC, useEffect } from "react";
import { Form, Input } from "antd";
import { QuestionTextAreaType } from "./interface";

const { TextArea } = Input;
const PropComponent: FC<QuestionTextAreaType> = (props: QuestionTextAreaType) => {
  const { title, placeholder, onChange, disabled } = props;
  const [form] = Form.useForm();
  useEffect(() => {
    form.setFieldsValue({ title, placeholder });
  }, [title, placeholder]);

  function handleValueChange() {
    if (onChange) {
      onChange(form.getFieldsValue());
    }
  }

  return (
    <Form
      layout="vertical"
      onValuesChange={handleValueChange}
      initialValues={{ title, placeholder }}
      disabled={disabled}
      form={form}>
      <Form.Item label="标题" name="title" rules={[{ required: true, message: "请输入标题" }]}>
        <Input />
      </Form.Item>
      <Form.Item label="placeholder" name="placeholder">
        <TextArea></TextArea>
      </Form.Item>
    </Form>
  );
};
export default PropComponent;
